package com.journey.org.ui.home.news.list

import android.os.Bundle
import com.journey.org.entity.Imgextra
import com.journey.org.entity.NeteaseNewsEntity
import com.journey.org.ui.home.news.detail.NewsDetailFragment
import com.mvvmhabit.org.base.MultiItemViewModel
import com.mvvmhabit.org.binding.command.BindingAction
import com.mvvmhabit.org.binding.command.BindingCommand

/**
 * @Date: 2020/11/23 9:40
 * @Author:小妖
 * @Description: 新闻列表
 */
class NewsListThreeItemViewModel(
    vm: NewsListViewModel,
    val entity: NeteaseNewsEntity
) :
    MultiItemViewModel<NewsListViewModel>(vm) {

    var firstImgUrl = ""
    var centerImgUrl = ""
    var endImgUrl = ""

    init {
        if (entity.imgextra != null) {
            for (index in entity.imgextra.indices) {
                when (index) {
                    0 -> {
                        firstImgUrl = entity.imgextra[index].imgsrc
                    }
                    1 -> {
                        centerImgUrl = entity.imgextra[index].imgsrc
                    }
                    2 -> {
                        endImgUrl = entity.imgextra[index].imgsrc
                    }
                }
            }
        }
    }

    val onEnterDetailCommand = BindingCommand<Any>(object : BindingAction {
        override fun call() {
            if (entity.docid != null && entity.docid != "") {
                val bundle = Bundle()
                bundle.putString("id", entity.docid)
                viewModel.startContainerActivity(NewsDetailFragment::class.qualifiedName, bundle)
            }
        }
    })

}